{include file="public/header" /}

<div class="page">
    <div class="fixed-bar">
        <div class="item-title">
            <div class="subject">
                <h3>项目定制</h3>
                <h5></h5>
            </div>
            {include file="public/admin_items" /}
        </div>
    </div>
<!--    action=" {if isset($edit_goods_sign)}{:url('Sellergoodsoffline/edit_save_goods')}{else/}{:url('Sellergoodsoffline/save_choose_eare')}{/if}"-->

        <form id="brand_form" action=" {if isset($edit_goods_sign)}{:url('Goodproject/projec_edit')}{else/}{:url('Goodproject/add')}{/if}"  method="post" name="form1" enctype="multipart/form-data">
            <input type="hidden" name="project_id" value="{$brand_array.project_id}" />
            <table class="ds-default-table">
                <tbody>
                 <!-- <tr class="noborder">
                  <td class="required"><label class="validation">商品绑定:</label></td>
                   <td><a href="javascript:void(0);" onclick="
                   edit_band_goods({$brand_array['project_id']});" class="dsui-btn-edit"><i class="iconfont"></i>选择需要绑定的商品</a></td>
                </tr> -->
                <tr class="noborder">
                    <td class="required w120"><label class="validation">项目定制标题:</label></td>
                    <td class="vatop rowform"><input type="text" value="{$brand_array.project_title}" name="project_title" id="project_title" class="txt">
                        </td>
                    <td class="vatop tips"></td>
                </tr>
                 <tr class="noborder">
                     <td class="required w120"><label class="validation">项目定制总价:</label></td>
                     <td class="vatop rowform"><input type="text" value="{$brand_array.total_price}" name="total_price" id="total_price" class="txt"></td>
                     <td class="vatop tips"></td>
                 </tr>
                 <tr class="noborder">
                     <td class="required w120"><label class="validation">咨询费:</label></td>
                     <td class="vatop rowform"><input type="text" value="{$brand_array.fee_price}" name="fee_price" id="fee_price" class="txt"></td>
                     <td class="vatop tips"></td>
                 </tr>
                 <tr class="noborder">
                     <td class="required w120"><label class="validation">服务费:</label></td>
                     <td class="vatop rowform"><input type="text" value="{$brand_array.charge_price}" name="charge_price" id="charge_price" class="txt"></td>
                     <td class="vatop tips"></td>
                 </tr>
                 <tr class="noborder">
                     <td class="required w120"><label class="validation">实施费:</label></td>
                     <td class="vatop rowform"><input type="text" value="{$brand_array.plementation_price}" name="plementation_price" id="plementation_price" class="txt"></td>
                     <td class="vatop tips"></td>
                 </tr>
                 <tr class="noborder">
                 <td class="required"><label for="typeid" class="validation">项目定制分类:</label></td>
                 <td class="vatop">
                     <label>
                         <select name="project_class" id="typeid" style="width: 222px;">
                             <option value="">{$Think.lang.ds_please_choose}</option>
                             {foreach name="project_class" item="cate"}
                             <option value="{$cate.id}" {if  ($cate.id == $brand_array.project_class) } selected {/if} >{$cate.name|default=''}</option>
                             {/foreach}
                         </select>
                     </label>
                 </td>
            <!-- 默认图片-->
            <td class="vatop tips"></td>
                 </tr>
                 <tr class="noborder"  id="video_type">
                     <td class="required w120">视频默认图片:</td>
                     <td class="vatop rowform">
                        <div class="dssc-goods-default-pic">
                             <div class="goodspic-uplaod">
                                 <span></span>
                                 {if $brand_array.default_images}
                                    <img width="300px" height="200px" src="{$http_name}/{$brand_array.default_images}" />
                                 {/if}
                                 <input type="hidden" name="default_images" id="default_images_name">

                                 <input type="file" hidefocus="true" name="default_images" id="default_images" data-action="{:url('Goodproject/ajax_videos')}">
                                 </span>
                                 <p class="hint"></p>
                             </div>
                         </div>
                         
                         <div id="dataLoading" class="wp_data_loading">
                             <div class="data_loading"></div>
                         </div>
                         <div id="demo">
                         </div>
                     </td>
                 </tr>

            <!-- 添加视频-->
                <tr class="noborder"  id="video_type" >
                    <td class="required w120">项目视频:</td>
                    <td class="vatop rowform">
                        <div class="dssc-goods-default-pic">
                            <div class="goodspic-uplaod">
                                <span></span>
                                {if $brand_array.project_videos}
                                <video width="300" height="300" controls>
                                        <source src="{$http_name}/{$brand_array.project_videos}" type="video/mp4">
                                </video>
                                {/if}
                                <input type="hidden" name="videoss" id="videos_name"
                                       />
                                <input type="file" hidefocus="true" name="videoss" id="videoss" data-action="{:url('Goodproject/ajax_video')}">
                                </span>
                                <p class="hint"></p>
                            </div>
                        </div>
                        <div id="dataLoading" class="wp_data_loading">
                            <div class="data_loading"></div>
                        </div>
                        <div id="demo">
                        </div>
                    </td>
                </tr>
            

            {if empty($brand_array.project_images)}
                 <tr class="noborder"  id="video_type">
                     <td class="required w120">项目图片:</td>
                     <td class="vatop rowform">
                         <div class="dssc-goods-default-pic">
                             <div class="goodspic-uplaod">
                                 <span></span>
                                 <input type="hidden" name="videos" id="video_name">

                                 <input type="file" hidefocus="true" name="video" id="videos" data-action="{:url('Goodproject/ajax_videos')}">
                                 </span>
                                 <p class="hint"></p>
                             </div>
                         </div>
                         <div id="dataLoading" class="wp_data_loading">
                             <div class="data_loading"></div>
                         </div>
                         <div id="demo">
                         </div>
                     </td>
                 </tr>
            {else if/}
                 <tr class="noborder"  id="video_type">
                     <td class="required w120">项目图片:</td>
                     <td class="vatop rowform">
                         <div class="dssc-goods-default-pic">
                             <div class="goodspic-uplaod">
                                 <span></span>
                                 <img width="300px" height="200px" src="{$http_name}/{$brand_array.project_images}" />
                                 <input type="hidden" name="videos" id="video_name">

                                 <input type="file" hidefocus="true" name="video" id="videos" data-action="{:url('Goodproject/ajax_videos')}">
                                 </span>
                                 <p class="hint"></p>
                             </div>
                         </div>
                         <div id="dataLoading" class="wp_data_loading">
                             <div class="data_loading"></div>
                         </div>
                         <div id="demo">
                         </div>
                     </td>
                 </tr>
            {/if}
            {if empty($brand_array.science)}
            <tr>
                <td colspan="2" class="required" id="parts2"><label>项目描述:</label>
                    <textarea value=""  name="science" id="science" style="margin-left: 84px;width: 500px;height: 122px;">{$brand_array.science}</textarea>
                </td>
                <td class="vatop tips"></td>
            </tr>
            {else if/}
            <tr>
                <td colspan="2" class="required" id="parts2"><label>项目描述:</label>
                    <textarea value=""  name="science" id="science" style="margin-left: 84px;width: 500px;height: 129px;">{$brand_array.science}</textarea>
                </td>
                <td class="vatop tips"></td>
            </tr>
            {/if}
            <tr class="noborder">
                    <td class="required">项目介绍</td>
                    {:build_editor(['name'=>'article_content','content'=>htmlspecialchars_decode($brand_array.project_describe)])}
                    <td class="vatop rowform" colspan="2"><textarea name="article_content" id="article_content" style="width:100%;"></textarea></td>
            </tr>
            <tr>
                <td class="required">图片上传:</td>
                <td id="divComUploadContainer">
                    <input type="hidden" name="fileupload" id="fileupload_name">
                    <input type="file" hidefocus="true" name="fileupload" id="fileupload" data-action="{:url('Goodproject/ajax_videos')}">
                <td class="vatop tips"></td>
            </tr>
            <tr>
                <td class="required">已传图片:</td>
                <td><div class="tdare">
                    <table width="600px" cellspacing="0" class="dataTable">
                        <tbody id="thumbnails">
                        {notempty name="file_upload"}
                        {foreach name="file_upload" item="v"}
                        <tr id="{$v.upload_id}" class="tatr2">
                            <input type="hidden" name="file_id[]" value="{$v.upload_id}" />
                            <td><img width="40px" height="40px" src="{$Think.UPLOAD_SITE_URL}/{$Think.ATTACH_ARTICLE}/{$v.file_name}" /></td>
                            <td>{$v.file_name}</td>
                            <td><a href="javascript:insert_editor('{$Think.UPLOAD_SITE_URL}/{$Think.ATTACH_ARTICLE}/{$v.file_name}');">321321</a> | <a href="javascript:del_file_upload('{$v.upload_id}');">{$Think.lang.ds_del}</a></td>
                        </tr>
                        {/foreach}
                        {/notempty}
                        </tbody>
                    </table>
                </div></td>
                <td class="vatop tips"></td>
            </tr>
            <!-- <tr class="noborder"> 
                <td class="required">项目介绍：</td>
                {:build_editor(['name'=>'article_content'])}
                <td class="vatop rowform" colspan="2"><textarea name="project_describe" id="article_content" style="width:100%;height:300px;">{$brand_array.project_describe}</textarea></td>
            </tr> -->
                <tr class="noborder">
                    <td class="required">上下架: </td>
                    <td class="vatop rowform onoff">
                        <label for="brand_recommend1" class="cb-enable {if $brand_array.status == '1'}selected{/if}" title="{$Think.lang.ds_yes}"><span>上架</span></label>
                        <label for="brand_recommend0" class="cb-disable {if $brand_array.status == '0'}selected{/if}" title="{$Think.lang.ds_no}"><span>下架</span></label>
                        <input id="brand_recommend1" name="status" {if $brand_array.status == '1'}checked="checked"{/if} value="1" type="radio">
                        <input id="brand_recommend0" name="status" {if $brand_array.status == '0'}checked="checked"{/if} value="0" type="radio"></td>
                </tr>
 
                <tr>
                    
                </tr>
                </tbody>
                <tfoot>
                <tr class="tfoot" style="text-align:center;">
                    <td colspan="15" ><input style="display:inline-block;border:none;padding:0px 18px;height:38px;line-height:38px;border-radius:3px;background-color:#419dfd;color:#fff!important;vertical-align:middle;text-align:center;cursor:pointer;font-size: 14px;" class="btn"  type="submit" value="{$Think.lang.ds_submit}"/></td>
                </tr>
                </tfoot>
            </table>
        </form>
    </div>

<script src="{$Think.PLUGINS_SITE_ROOT}/mlselection.js"></script>
<script src="{$Think.PLUGINS_SITE_ROOT}/layui/layui.js"></script>
<script>
    $(function () {
        jQuery.validator.addMethod("checkFCodePrefix", function (value, element) {
            return this.optional(element) || /^[a-zA-Z]+$/.test(value);
        }, '<i class="iconfont">&#xe64c;</i>{$Think.lang.prompt_information1}');

        $('#brand_form').validate({
            errorPlacement: function (error, element) {
                $(element).nextAll('p').append(error);
            },
            rules : {

                project_title: {
                    required: true,
                },
            },
            messages : {

                project_title: {
                    required: '名称不能为空'
                },
            }
        });



    });
    $(function() {
        $('#type_div').perfectScrollbar();
        $("#pic").change(function() {
            $("#textfield1").val($(this).val());
        });
        $('input[type="radio"][name="cat_id"]').click(function() {
            if ($(this).val() == '0') {
                $('#t_name').val('');
            } else {
                $('#t_name').val($(this).next('span').html());
            }
        });
        
        //上传图片
        $(document).on('change', '#videos', function () {

            // $('#dataLoading').show();
            var files = document.getElementById('videos').files[0];

            var formData = new FormData();
            var obj = $(this);
            formData.append('file', files);
            var url = $(this).attr('data-action');
            $.ajax({
                //请求方式
                type: "POST",
                //请求地址
                url: url,
                data: formData,
                cache: false,  //默认是true，但是一般不做缓存
                processData: false, //用于对data参数进行序列化处理，这里必须false；如果是true，就会将FormData转换为String类型
                contentType: false,  //一些文件上传http协议的关系，自行百度，如果上传的有文件，那么只能设置为false
                //请求成功
                success: function (result) {

                    if (result.msg == 1) {
                        $('.vide').empty();
                        $('#dataLoading').hide();
                        layer.msg('上传成功');
                        $("#video_name").val(result.files_name);
                        // $("type[name='old_filename']").val(result.old_name);
                    } else {
                        obj.val('');
                        $('#dataLoading').hide();
                        layer.msg('文件信息错误,请重新上传');
                        return false;
                    }

                },
                //请求失败，包含具体的错误信息
                error: function (e) {
                    console.log(e.status);
                    console.log(e.responseText);
                }
            });

        });

        //上传默认图片
        $(document).on('change', '#default_images', function () {

            // $('#dataLoading').show();
            var files = document.getElementById('default_images').files[0];

            var formData = new FormData();
            var obj = $(this);
            formData.append('file', files);
            var url = $(this).attr('data-action');
            $.ajax({
                //请求方式
                type: "POST",
                //请求地址
                url: url,
                data: formData,
                cache: false,  //默认是true，但是一般不做缓存
                processData: false, //用于对data参数进行序列化处理，这里必须false；如果是true，就会将FormData转换为String类型
                contentType: false,  //一些文件上传http协议的关系，自行百度，如果上传的有文件，那么只能设置为false
                //请求成功
                success: function (result) {

                    if (result.msg == 1) {
                        $('.vide').empty();
                        $('#dataLoading').hide();
                        layer.msg('上传成功');
                        $("#default_images_name").val(result.files_name);
                        // $("type[name='old_filename']").val(result.old_name);
                    } else {
                        obj.val('');
                        $('#dataLoading').hide();
                        layer.msg('文件信息错误,请重新上传');
                        return false;
                    }

                },
                //请求失败，包含具体的错误信息
                error: function (e) {
                    console.log(e.status);
                    console.log(e.responseText);
                }
            });

        });
        //上传视频
        $(document).on('change', '#videoss', function () {

            // $('#dataLoading').show();
            var files = document.getElementById('videoss').files[0];

            var formData = new FormData();
            var obj = $(this);
            formData.append('file', files);
            var url = $(this).attr('data-action');
            $.ajax({
                //请求方式
                type: "POST",
                //请求地址
                url: url,
                data: formData,
                cache: false,  //默认是true，但是一般不做缓存
                processData: false, //用于对data参数进行序列化处理，这里必须false；如果是true，就会将FormData转换为String类型
                contentType: false,  //一些文件上传http协议的关系，自行百度，如果上传的有文件，那么只能设置为false
                //请求成功
                success: function (result) {

                    if (result.msg == 1) {
                        $('.vide').empty();
                        $('#dataLoading').hide();
                        layer.msg('上传成功');
                        $("#videos_name").val(result.files_name);
                        // $("type[name='old_filename']").val(result.old_name);
                    } else {
                        obj.val('');
                        $('#dataLoading').hide();
                        layer.msg('文件信息错误,请重新上传');
                        return false;
                    }

                },
                //请求失败，包含具体的错误信息
                error: function (e) {
                    console.log(e.status);
                    console.log(e.responseText);
                }
            });

        });

        $(document).on('change', '#fileupload', function () {

            // $('#dataLoading').show();
            var files = document.getElementById('fileupload').files[0];

            var formData = new FormData();
            var obj = $(this);
            formData.append('file', files);
            var url = $(this).attr('data-action');
            $.ajax({
                //请求方式
                type: "POST",
                //请求地址
                url: url,
                data: formData,
                cache: false,  //默认是true，但是一般不做缓存
                processData: false, //用于对data参数进行序列化处理，这里必须false；如果是true，就会将FormData转换为String类型
                contentType: false,  //一些文件上传http协议的关系，自行百度，如果上传的有文件，那么只能设置为false
                //请求成功
                success: function (result) {

                    if (result.msg == 1) {
                        $('.vide').empty();
                        $('#dataLoading').hide();
                        layer.msg('上传成功');
                        $("#video_name").val(result.files_name);
                        add_uploadedfile(result);
                        // $("type[name='old_filename']").val(result.old_name);
                    } else {
                        obj.val('');
                        $('#dataLoading').hide();
                        layer.msg('文件信息错误,请重新上传');
                        return false;
                    }

                },
                //请求失败，包含具体的错误信息
                error: function (e) {
                    console.log(e.status);
                    console.log(e.responseText);
                }
            });

        });


    });
    $(document).ready(function(){
        $('.edit_gcategory').click(function(){
            $('input[name="class_id"]').val('');
            $('input[name="brand_class"]').val('');
        });
        var textButton1="<input type='text' name='textfield' id='textfield1' class='type-file-text' /><input type='button' name='button' id='button1' value='' class='type-file-button' />"
        $(textButton1).insertBefore("#project_images");
        $("#project_images").change(function(){$("#textfield1").val($("#project_images").val());});
        jQuery.validator.addMethod("initial", function(value, element) {
            return /^[A-Za-z0-9]$/i.test(value);
        }, "");
        $("form").submit(function(e){
            var res =  $("#brand_form").valid();
            var url = $('form').attr('action');
            $.ajax({
                type: "POST",
                url:url,
                data:$('#brand_form').serialize(),// 你的formid
                error: function(request) {
                    alert("Connection error");
                },
                success: function(result) {
                    if(result.code==0){
                        layer.msg(result.msg);
                        location.href=result.url;return false;
                    }else{
                        layer.msg(result.msg);
                        location.href=result.url;return false;

                    }
                }
            });
            return false;

        });

    });
    function add_uploadedfile(file_data)
    {
        var newImg = '<tr id="' + file_data.msg + '" class="tatr2"><input type="hidden" name="file_id[]" value="' + file_data.files_path + '" /><td><img width="40px" height="40px" src="' + file_data.files_path + '" /></td><td>' + file_data.files_name + '</td><td><a href="javascript:insert_editor(\'' + file_data.files_path + '\');">插入编辑器</a> </td></tr>';
        $('#thumbnails').prepend(newImg);
    }
    function insert_editor(file_path){
        ue.execCommand('insertimage', {src:file_path});
    }
    function del_file_upload(file_id)
    {
        layer.confirm('{$Think.lang.ds_ensure_del}', {
            btn: ['{$Think.lang.ds_ok}', '{$Think.lang.ds_cancel}'],
            title: false,
        }, function () {
            $.getJSON("{:url('Information/ajax')}",{branch:'del_file_upload',file_id: + file_id}, function(result){
                if(result){
                    $('#' + file_id).remove();
                    layer.msg('{$Think.lang.ds_common_del_succ}');
                }else{
                    layer.alert('{$Think.lang.article_index_del_fail}');
                }
            });
        });
    }

    function call_back(picname){
        $('#brand_pic').val(picname);
        $('#view_img').attr('src','{$Think.UPLOAD_SITE_URL}/{$Think.ATTACH_BRAND}/'+picname);
    }


    var typeScroll = 0;

    function type_scroll(o) {
        var id = o.val();
        if (!$('#type_dt_' + id).is('dt')) {
            return false;
        }
        $('#type_div').scrollTop(-typeScroll);
        var sp_top = $('#type_dt_' + id).offset().top;
        var div_top = $('#type_div').offset().top;
        $('#type_div').scrollTop(sp_top - div_top);
        typeScroll = sp_top - div_top;
    }

    gcategoryInit('gcategory');

    function edit_band_goods(ids_str) {

        _uri = ADMINSITEURL+"/Goodproject/edit_band_goods?projectid=" + ids_str;
        dsLayerOpen(_uri,'绑定商品','600px','400px');
    }
</script>